﻿using DataAccess.Ads;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FOModels.Ads;
using System.Data;
namespace Bussiness.Ads
{
    public class AdsBLL
    {
        private AdsDAL dal;
        public AdsBLL()
        {
            dal = new AdsDAL();
        }
        public List<AdsModels> getAdsToManager(int langid)
        {
            List<AdsModels> list = new List<AdsModels>();
            AdsModels fur;
            DataTable tb = dal.getAdsToManager(langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new AdsModels();
                    fur.AdsID = int.Parse(row["AdsID"].ToString());
                    fur.AdsPageID = int.Parse(row["AdsPageID"].ToString());
                    fur.AdsPositionID = int.Parse(row["AdsPositionID"].ToString());
                    fur.AdsActive = bool.Parse(row["AdsActive"].ToString());
                    fur.AdsUrlImgInfo = row["AdsUrlImgInfo"].ToString();
                    fur.AdsName = row["AdsName"].ToString();
                    fur.AdsImg = row["AdsImg"].ToString();
                    fur.AdsImgInfo = row["AdsImgInfo"].ToString();
                    fur.FlagImage = row["FlagImage"].ToString();
                    fur.AdsPageName = row["AdsPageName"].ToString();
                    fur.AdsPositionName = row["AdsPositionName"].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public AdsModels getAdsByIDToManager(int AdsID,int langid)
        {
            AdsModels fur = new AdsModels();
            DataTable tb = dal.getAdsByIDToManager(AdsID,langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur.AdsID = int.Parse(row["AdsID"].ToString());
                    fur.AdsPageID = int.Parse(row["AdsPageID"].ToString());
                    fur.AdsPositionID = int.Parse(row["AdsPositionID"].ToString());
                    fur.AdsActive = bool.Parse(row["AdsActive"].ToString());
                    fur.AdsUrlImgInfo = row["AdsUrlImgInfo"].ToString();
                    fur.AdsName = row["AdsName"].ToString();
                    fur.AdsImg = row["AdsImg"].ToString();
                    fur.AdsImgInfo = row["AdsImgInfo"].ToString();
                }
            }
            return fur;
        }
        public AdsModels getAdsByPageID(int AdsPageID, int AdsPositionID, int langid)
        {
            AdsModels fur = new AdsModels();
            DataTable tb = dal.getAdsByPageID(AdsPageID,AdsPositionID, langid);
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur.AdsID = int.Parse(row["AdsID"].ToString());
                    fur.AdsPageID = int.Parse(row["AdsPageID"].ToString());
                    fur.AdsPositionID = int.Parse(row["AdsPositionID"].ToString());
                    fur.AdsActive = bool.Parse(row["AdsActive"].ToString());
                    fur.AdsUrlImgInfo = row["AdsUrlImgInfo"].ToString();
                    fur.AdsName = row["AdsName"].ToString();
                    fur.AdsImg = row["AdsImg"].ToString();
                    fur.AdsImgInfo = row["AdsImgInfo"].ToString();
                }
                return fur;
            }
            else
                return null;
         
        }
        public List<AdsPageModels> getAdsPage()
        {
            List<AdsPageModels> list = new List<AdsPageModels>();
            AdsPageModels fur;
            DataTable tb = dal.getAdsPage();
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new AdsPageModels();
                    fur.AdsPageID = int.Parse(row["AdsPageID"].ToString());
                    fur.AdsPageName = row["AdsPageName"].ToString();
                    fur.AdsPageDescription = row["AdsPageDescription"].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public List<AdsPositionModels> getAdsPosition()
        {
            List<AdsPositionModels> list = new List<AdsPositionModels>();
            AdsPositionModels fur;
            DataTable tb = dal.getAdsPosition();
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur = new AdsPositionModels();
                    fur.AdsPositionID = int.Parse(row["AdsPositionID"].ToString());
                    fur.AdsPositionName = row["AdsPositionName"].ToString();
                    fur.AdsPositionDescription = row["AdsPositionDescription"].ToString();
                    list.Add(fur);
                }
            }
            return list;
        }
        public AdsModels getTop1Ads()
        {
            AdsModels fur = new AdsModels();
            DataTable tb = dal.getTop1Ads();
            if (tb != null && tb.Rows.Count > 0)
            {
                foreach (DataRow row in tb.Rows)
                {
                    fur.AdsID = int.Parse(row["AdsID"].ToString());
                }
                return fur;
            }
            else
                return null;
        }
        public int UpdateAds(AdsModels models, int langid)
        {
            if (dal.UpdateAds(models) > 0 && dal.UpdateAdsLang(models, langid) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int InsertAds(AdsModels models)
        {
            if (dal.InsertAds(models) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int InsertAdsLang(AdsModels models, int langid)
        {
            if (dal.InsertAdsLang(models, langid) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
        public int DeleteAds(int AdsID)
        {
            if (dal.DeleteAds(AdsID) > 0 && dal.DeleteAdsLang(AdsID) > 0)
            {
                return 1;
            }
            else
            {
                return -1;
            }
        }
    }
}
